﻿package classes 
{
	import classes.*;
	import commands.abCommand;
	import commands.CommandType;
	import commands.LoginCmdReq;
	import commands.LoginCmdRsp;
	import flash.display.MovieClip;
	import flash.display.*;
	import flash.text.*;
	//import flash.text.engine.RenderingMode;
	import flash.events.MouseEvent;
	import flash.utils.ByteArray;
	import commands.*;
	
	import commands.classesinfo.*;	
	
	/**
	 * ...
	 * @author wwx
	 */
	public class NetWork extends MovieClip
	{
		//private var _tcpSocket:TCPSocket;
		
		//private var _btConnet:Button;
		//private var _btSend:Button;
		private var _btLogin:TextField;
		private var _cmdTransfer:CommandTransfer;
		private var _roomId:int;
		private var _deskId:int;
		private var _deskPos:int;
		private var UserParam:String = root.loaderInfo.parameters["UserParam"];
		
		public function NetWork() 
		{
			UserParam = root.loaderInfo.parameters["UserParam"];
			/*
			var bt:TextField = new TextField();
			bt.text = "connect";
			bt.x = 10;
			bt.y = 10;
			bt.addEventListener(MouseEvent.CLICK, clickConnect);
			addChild(bt);
			
			bt = new TextField();
			bt.text = "send";
			bt.x = 10;
			bt.y = 100;
			bt.addEventListener(MouseEvent.CLICK, clickSend);
			addChild(bt);
			
			_tcpSocket = null;
			*/
			
			_btLogin = new TextField();
			_btLogin.text = "getrooms";
			_btLogin.x = 0;
			_btLogin.y = 0;

			_btLogin.addEventListener(MouseEvent.CLICK, getroomsInfo);
			addChild(_btLogin);
			
			_btLogin = new TextField();
			_btLogin.text = "logout";
			_btLogin.x = 0;
			_btLogin.y = 20;
			_btLogin.addEventListener(MouseEvent.CLICK, logout);
			addChild(_btLogin);			
			
			_btLogin = new TextField();
			_btLogin.text = "enterRoom";
			_btLogin.x = 0;
			_btLogin.y = 40;
			_btLogin.addEventListener(MouseEvent.CLICK, enterRoom);
			addChild(_btLogin);		
			
			_btLogin = new TextField();
			_btLogin.text = "exitRoom";
			_btLogin.x = 0;
			_btLogin.y = 60;
			_btLogin.addEventListener(MouseEvent.CLICK, exitRoom);
			addChild(_btLogin);	

			_btLogin = new TextField();
			_btLogin.text = "enterDesk";
			_btLogin.x = 0;
			_btLogin.y = 80;
			_btLogin.addEventListener(MouseEvent.CLICK, enterDesk);
			addChild(_btLogin);	
			
			_btLogin = new TextField();
			_btLogin.text = "exitDesk";
			_btLogin.x = 0;
			_btLogin.y = 100;
			_btLogin.addEventListener(MouseEvent.CLICK, exitDesk);
			addChild(_btLogin);		
			
			_btLogin = new TextField();
			_btLogin.text = "startPlay";
			_btLogin.x = 0;
			_btLogin.y = 120;
			_btLogin.addEventListener(MouseEvent.CLICK, startPlay);
			addChild(_btLogin);	
			
			_btLogin = new TextField();
			_btLogin.text = "inject";
			_btLogin.x = 0;
			_btLogin.y = 140;
			_btLogin.addEventListener(MouseEvent.CLICK, inject);
			addChild(_btLogin);	
			
			_btLogin = new TextField();
			_btLogin.text = "addChip";
			_btLogin.x = 0;
			_btLogin.y = 160;
			_btLogin.addEventListener(MouseEvent.CLICK, addChip);
			addChild(_btLogin);			
			
			_btLogin = new TextField();
			_btLogin.text = "sohandle";
			_btLogin.x = 0;
			_btLogin.y = 180;
			_btLogin.addEventListener(MouseEvent.CLICK, sohandle);
			addChild(_btLogin);			
			
			_btLogin = new TextField();
			_btLogin.text = "giveup";
			_btLogin.x = 0;
			_btLogin.y = 200;
			_btLogin.addEventListener(MouseEvent.CLICK, giveup);
			addChild(_btLogin);	
			
			_btLogin = new TextField();
			_btLogin.text = "follow";
			_btLogin.x = 0;
			_btLogin.y = 220;
			_btLogin.addEventListener(MouseEvent.CLICK, follow);
			addChild(_btLogin);		
			
			_btLogin = new TextField();
			_btLogin.text = "pass";
			_btLogin.x = 0;
			_btLogin.y = 240;
			_btLogin.addEventListener(MouseEvent.CLICK, pass);
			addChild(_btLogin);		
			
			
			var temp:TextField = new TextField();
			if(null == UserParam)
				temp.text = "null";
			else
				temp.text = UserParam;
			temp.x = 150;
			temp.y = 0;
			temp.width = 500;
			temp.height = 200;
			temp.multiline = true;
			addChild(temp);
			//创建命令对象，并连接服务器。
				var xml:String = "<UserInfo id=\"1\" name=\"www\" password=\"123456\">\n" + 
					"<\/UserInfo>\n" + 
					"<GameInfo id=\"1\">\n" + 
					"<\/GameInfo>\n" +
					"<DServers>\n" +
					"<DServer ip=\"192.168.1.103\" port=\"8000\" \/>\n" +
					"<\/DServers>";	
				temp = new TextField();
					temp.text = xml;
					temp.x = 150;
					temp.y = 150;
					temp.width = 500;
					temp.height = 200;
					temp.multiline = true;
					addChild(temp);
			if(null == UserParam)
				UserParam = xml;
			_cmdTransfer = new CommandTransfer(recvCmd, UserParam);

/*			
			var ret:int = _cmdTransfer.connectToServer("192.168.1.103", 8001);
			if (0 == ret)
			{
				trace("Connect to Server sus!");
			}
			else
			{
				trace("Connect to Server failed!");
			}
*/			
		}
		
/*		
		private function clickConnect(e:MouseEvent) :void
		{
			trace("You clicked the clickConnect!");
			if (null != _tcpSocket)
			{
				//return;
				_tcpSocket.close();
			}
			_tcpSocket = new TCPSocket("192.168.1.103", 8080, recvDataCallback);
			_tcpSocket.connect();
		}
*/		
		private function clickSend(e:MouseEvent) :void
		{
			trace("You clicked the clickSend!");
			

			
		}
		
		private function connected(cmd:ConnectStatusRsp):int
		{
			trace("\n\n-------connected-------\n");
			trace("status = " + cmd.status);
			return 0;
		}
		
		//发送获取房间命令
		private function getroomsInfo(e:MouseEvent):void
		{
			var getRoomsCmd:GetRoomsOfGameReq = new GetRoomsOfGameReq();
			getRoomsCmd.gameId = _cmdTransfer.getGameID();
			var ret:int = _cmdTransfer.sendCmdToServer(getRoomsCmd);
			if (0 == ret)
			{
				trace("send getRoomsInfo command sus!");
			}
			else
			{
				trace("send getRoomsInfo command failed!");
			}	
		}
		
		//发送获取房间返回
		private function getroomsInfoRsp(cmd:GetRoomsOfGameRsp):int
		{
			trace("\n\n-------GetRoomsOfGameRsp-------\n");
			trace("GetRoomsOfGameRsp error = " + cmd.errorNum);				
			if (0 != cmd.errorNum)
			{
				return 0;
			}
			var roomCount:int = cmd.infoOfRooms.length;
			trace("count of room = " + roomCount);	
			var roomInfo:DirectoryRoomInfo = null;
			for (var i:int = 0; i < roomCount; i++)
			{
				roomInfo = cmd.infoOfRooms[i] as DirectoryRoomInfo;
				if (null == roomInfo)
					continue;
				trace("id = " + roomInfo.id + 
						",maxChip=" + roomInfo.maxChip +
						",minChip=" + roomInfo.minChip +
						",maxPlayer=" + roomInfo.maxPlayer +
						",curPlayer=" + roomInfo.curPlayer +
						",gateId=" + roomInfo.gateId + 
						",gateIP=" + roomInfo.gateIp +
						",gatePort=" + roomInfo.gatePort);	
			}
			return 0;
		}
		
		private function logout(e:MouseEvent):void
		{
			var logout:LogoutCmdReq = new LogoutCmdReq();
			
			var ret:int = _cmdTransfer.sendCmdToServer(logout);
			if (0 == ret)
			{
				trace("send logout command sus!");
			}
			else
			{
				trace("send logout command failed!");
			}			
		}
		
		private function loginRsp(cmd:LoginCmdRsp):int
		{
			trace("\n\n-------loginRsp-------\n");
			trace("loginRsp error = " + cmd.errorNum);			
			/*var roomInfo:RoomInfo = null;
			for (var i:int = 0; i < cmd.rooms.length; i++)
			{				
				roomInfo = cmd.rooms[i] as RoomInfo;
				trace("room id=" + roomInfo.id 
				+ " maxPlayer=" + roomInfo.maxPlayer 
				+ " curPlayer=" + roomInfo.curPlayer
				+ " maxChip=" + roomInfo.maxChip
				+ " minChip=" + roomInfo.minChip
				+ "\n");
				
				_roomId = roomInfo.id;
			}*/
			return 0;
		}
		
		private function logoutRsp(cmd:LogoutCmdRsp):int
		{
			trace("logoutRsp error = " + cmd.errorNum + "\n");
			return 0;
		}
		
		private function enterRoom(e:MouseEvent):void
		{
			var enterRoom:EnterRoomCmdReq = new EnterRoomCmdReq();
			enterRoom.roomId = 0;// _roomId;
			var ret:int = _cmdTransfer.sendCmdToServer(enterRoom);
			if (0 == ret)
			{
				trace("send enterRoom command sus!");
			}
			else
			{
				trace("send enterRoom command failed!");
			}
		}
		
		private function enterRoomRsp(cmd:EnterRoomCmdRsp):int
		{
			trace("\n\n-------enterRoomRsp-------\n");
			var deskCount:int = cmd.desksInfo.length;
			trace("enterRoomRsp error = " + cmd.errorNum 
					+ "; deskCount = " + deskCount + "\n");
			var deskInfo:DeskInfo = null;
			for (var i:int = 0; i < cmd.desksInfo.length; i++)
			{
				deskInfo = cmd.desksInfo[i] as DeskInfo;
				trace("desk id= " + deskInfo.id
						+ "; desk status= " + deskInfo.status);
											
				_deskId = deskInfo.id;
				
				var seatCount:int = deskInfo.chairsInfo.length;
				var chairInfo:ChairInfo = null;
				for (var j:int = 0; j < seatCount; j++)
				{
					chairInfo = deskInfo.chairsInfo[j] as ChairInfo;
					trace("  座位id=" + chairInfo.id 
							+ ",玩家id=" + chairInfo.playerId
							+ ",玩家状态=" + chairInfo.playerStatus
							+ ",玩家名字=" + chairInfo.playerName);
					if (0 == chairInfo.playerId)
					{
						_deskPos = chairInfo.id;
					}
				}
			}
			return 0;
		}
		
		private function exitRoom(e:MouseEvent):void
		{
			var cmd:ExitRoomCmdReq = new ExitRoomCmdReq();
			cmd.reserve = 0;
			var ret:int = _cmdTransfer.sendCmdToServer(cmd);
			if (0 == ret)
			{
				trace("send exitRoom command sus!");
			}
			else
			{
				trace("send exitRoom command failed!");
			}			
		}
		
		private function exitRoomRsp(cmd:ExitRoomCmdRsp):int
		{
			trace("\n\n--------exitRoomRsp------\n");
			var roomCount:int = cmd.roomsInfo.length;
			trace("exitRoomRsp error = " + cmd.errorNum + "; ");
			trace("消息N = " + roomCount + "\n");
			var roomInfo:RoomInfo = null;
			for (var i:int = 0; i < roomCount; i++)
			{
				roomInfo = cmd.roomsInfo[i] as RoomInfo;
				trace("房间id= " + roomInfo.id 
						+ "限制人数=" + roomInfo.maxPlayer
						+ "当前人数=" + roomInfo.curPlayer
						+ "最低筹码=" + roomInfo.minChip
						+ "最高筹码=" + roomInfo.maxChip);			
			}
			return 0;
		}		
		
		private function enterDesk(e:MouseEvent):void
		{
			var cmd:EnterDeskCmdReq = new EnterDeskCmdReq();
			cmd.reserve = 0;
			cmd.deskId = _deskId;
			cmd.deskPosition = _deskPos;
			
			var ret:int = _cmdTransfer.sendCmdToServer(cmd);
			if (0 == ret)
			{
				trace("send enterDesk command sus!");
			}
			else
			{
				trace("send enterDesk command failed!");
			}			
		}
		
		private function enterDeskRsp(cmd:EnterDeskCmdRsp):int
		{
			trace("\n\n-------enterDeskRsp-------\n");
			var playerCount:int = cmd.playersInfo.length
			trace("错误号= " + cmd.errorNum 
					+ ",桌子id=" + cmd.deskId
					+ ",游戏状态=" + cmd.gameStatus
					+ "\n");
			var i:int = 0;
			trace("共牌信息:(count=" + cmd.publicCardsInfo.length + ")");
			var cardInfo:CardInfo = null;
			for (i = 0; i < cmd.publicCardsInfo.length; i++)
			{
				cardInfo = cmd.publicCardsInfo[i] as CardInfo;
				trace("    牌类型:" + cardInfo.colorOfCard + ",牌大小:" + cardInfo.contentOfCard);
			}
			
			var playerInfoInDesk:PlayerInfoInDesk = null;			
			trace("座位信息:(count=" +cmd.playersInfo.length + ")");
			for (i = 0; i < cmd.playersInfo.length; i++)
			{
				playerInfoInDesk = cmd.playersInfo[i] as PlayerInfoInDesk;
				trace("   座位id= " + playerInfoInDesk.seatId 
						+ ",玩家ID=" + playerInfoInDesk.playerId
						+ ",玩家名字=" + playerInfoInDesk.name
						+ ",状态=" + playerInfoInDesk.status
						+ ",显示/隐藏=" + playerInfoInDesk.isShow);
				for (var j:int = 0; j < playerInfoInDesk.cardInfo.length; j++)
				{
					cardInfo = playerInfoInDesk.cardInfo[i] as CardInfo;
					trace("      牌" + j + "的类型:" + cardInfo.colorOfCard 
								+ "牌" + j + "的大小:" + cardInfo.contentOfCard);
				}
			}
			return 0;
		}		
		
		
		private function exitDesk(e:MouseEvent):void
		{
			var cmd:ExitDeskCmdReq = new ExitDeskCmdReq();
			cmd.reserve = 0;
			
			var ret:int = _cmdTransfer.sendCmdToServer(cmd);
			if (0 == ret)
			{
				trace("send exitDesk command sus!");
			}
			else
			{
				trace("send exitDesk command failed!");
			}			
		}		
		
		private function exitDeskRsp(cmd:ExitDeskCmdRsp):int
		{
			trace("\n\n-------exitDeskRsp-------\n");
			//trace("错误号= " + cmd.errorNum 
					//+ ",桌子数量N=" + cmd.desksInfo.length);
			var i:int = 0;		
			var deskInfo:DeskInfo = null;			
			//for (i = 0; i < cmd.desksInfo.length; i++)
			{
				//deskInfo = cmd.desksInfo[i] as DeskInfo;
				//trace("   桌子id= " + deskInfo.id 
						//+ ",桌子状态=" + deskInfo.status
						//+ ",座位数量N=" + deskInfo.chairsInfo.length);
				var chairInfo:ChairInfo = null;		
				for (var j:int = 0; j < deskInfo.chairsInfo.length; j++)
				{
					chairInfo = deskInfo.chairsInfo[i] as ChairInfo;
					trace("      座位id=" + chairInfo.id 
						+ ",玩家id=" + chairInfo.playerId
						+ ",玩家名字=" + chairInfo.playerName 
						+ ",玩家状态=" + chairInfo.playerStatus);
				}
			}
			return 0;
		}
		
		private function startPlay(e:MouseEvent):void
		{
			var cmd:StartPlayCmdReq = new StartPlayCmdReq();
			cmd.reserve = 0;
			
			var ret:int = _cmdTransfer.sendCmdToServer(cmd);
			if (0 == ret)
			{
				trace("send startPlay command sus!");
			}
			else
			{
				trace("send startPlay command failed!");
			}			
		}		
		
		private function startPlayRsp(cmd:StartPlayCmdRsp):int
		{
			trace("\n\n-------startPlayRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			return 0;
		}
		
		private function inject(e:MouseEvent):void
		{
			var cmd:InjectCmdReq = new InjectCmdReq();
			cmd.reserve = 0;
			
			cmd.money = 500;
			
			var ret:int = _cmdTransfer.sendCmdToServer(cmd);
			if (0 == ret)
			{
				trace("send inject command sus!");
			}
			else
			{
				trace("send inject command failed!");
			}			
		}		
		
		private function injectRsp(cmd:InjectCmdRsp):int
		{
			trace("\n\n-------injectRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			return 0;
		}
		
		private function addChip(e:MouseEvent):void
		{
			var cmd:AddChipCmdReq = new AddChipCmdReq();
			cmd.reserve = 0;
			
			cmd.addChip = 10;
			
			var ret:int = _cmdTransfer.sendCmdToServer(cmd);
			if (0 == ret)
			{
				trace("send addChip command sus!");
			}
			else
			{
				trace("send addChip command failed!");
			}			
		}		
		
		private function addChipRsp(cmd:AddChipCmdRsp):int
		{
			trace("\n\n-------addChipRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			return 0;
		}
		
		private function sohandle(e:MouseEvent):void
		{
			var cmd:SoHandleCmdReq = new SoHandleCmdReq();
			cmd.reserve = 0;

			cmd.chip = 50;
			
			var ret:int = _cmdTransfer.sendCmdToServer(cmd);
			if (0 == ret)
			{
				trace("send sohandle command sus!");
			}
			else
			{
				trace("send sohandle command failed!");
			}			
		}		
		
		private function sohandleRsp(cmd:SoHandleCmdRsp):int
		{
			trace("\n\n-------sohandleRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			return 0;
		}
		
		private function giveup(e:MouseEvent):void
		{
			var cmd:GiveUpPlayCmdReq = new GiveUpPlayCmdReq();
			cmd.reserve = 0;

			cmd.chip = 10;
			
			var ret:int = _cmdTransfer.sendCmdToServer(cmd);
			if (0 == ret)
			{
				trace("send giveup command sus!");
			}
			else
			{
				trace("send giveup command failed!");
			}			
		}		
		
		private function giveupRsp(cmd:GiveUpPlayCmdRsp):int
		{
			trace("\n\n-------giveupRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			return 0;
		}
		
		private function follow(e:MouseEvent):void
		{
			var cmd:FollowCmdReq = new FollowCmdReq();
			cmd.reserve = 0;
			
			var ret:int = _cmdTransfer.sendCmdToServer(cmd);
			if (0 == ret)
			{
				trace("send follow command sus!");
			}
			else
			{
				trace("send follow command failed!");
			}			
		}		
		
		private function followRsp(cmd:FollowCmdRsp):int
		{
			trace("\n\n-------followRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			return 0;
		}
		
		private function pass(e:MouseEvent):void
		{
			var cmd:PassCmdReq = new PassCmdReq();
			cmd.reserve = 0;
			
			var ret:int = _cmdTransfer.sendCmdToServer(cmd);
			if (0 == ret)
			{
				trace("send pass command sus!");
			}
			else
			{
				trace("send pass command failed!");
			}			
		}		
		
		private function passRsp(cmd:PassCmdRsp):int
		{
			trace("\n\n-------passRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			return 0;
		}
		
		
		private function updateDeskInfoRsp(cmd:DeskInofUpdateCmd):int
		{
			trace("\n\n-------updateDeskInfoRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			trace("桌子id=" + cmd.deskId
					+ ",玩家id=" + cmd.playerId
					+ ",座位id=" + cmd.seatId
					+ ",类型type=" + cmd.type);
			if (1 == cmd.type)
			{
				trace("更新游戏状态,状态=" + cmd.status);
			}
			else if (2 == cmd.type)
			{
				trace("更新筹码:桌子上剩余筹码=" + cmd.remainChip
						+ ",总下注筹码=" + cmd.totalInjectChip
						+ ",总筹码=" + cmd.totalChip);
			}
			else if (3 == cmd.type)
			{
				trace("玩家进入:玩家名字=" + cmd.playerName);
			}
			else if (4 == cmd.type)
			{
				trace("玩家退出");
			}
			else if (5 == cmd.type)
			{
				trace("玩家赢得筹码:筹码值=" + cmd.winChips
						+ ",玩家牌类型=" + cmd.typeOfCard
						+ ",牌张数=" + cmd.cardsInfo.length);
				var cardInfo:CardInfo = null;
				for (var i:int = 0; i < cmd.cardsInfo.length; i++)
				{
					cardInfo = cmd.cardsInfo[i] as CardInfo;
					trace("    牌" + i + "的花色=" + cardInfo.colorOfCard
							+ ",牌大小=" + cardInfo.contentOfCard);
				}
			}
			return 0;
		}
		
		private function assignGroudCardRsp(cmd:AssignGroundCardCmd):int
		{
			trace("\n\n-------assignGroudCardRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			//var cardInfo:CardInfo = cmd.cardInfo[0] as CardInfo;
			trace("桌子id=" + cmd.deskId
					+ ",位置id=" + cmd.positionId
					+ ",底牌张数=" + cmd.cardsInfo.length);
			var cardInfo:CardInfo = null;
			for (var i:int = 0; i < cmd.cardsInfo.length; i++)
			{
				cardInfo = cmd.cardsInfo[i] as CardInfo;
				trace("  牌" + i + "的花色=" + cardInfo.colorOfCard
					+ ",牌大小=" + cardInfo.contentOfCard);
			}
			
			return 0;
		}
		
		private function assignPublicCardRsp(cmd:AssignPublicCardCmd):int
		{
			trace("\n\n-------assignPublicCardRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			
			trace("桌子id=" + cmd.deskId
					+ ",牌张数=" + cmd.cardsInfo.length);
				
			var cardInfo:CardInfo = null;
			for (var i = 0; i < cmd.cardsInfo.length; i++)
			{
				cardInfo = cmd.cardsInfo[0] as CardInfo;
				trace("    牌" + i + "的花色=" + cardInfo.colorOfCard
						+ ",牌大小=" + cardInfo.contentOfCard);
			}
			
			return 0;
		}
		
		private function sendTrunningCardRsp(cmd:SendTurnningCardCmd):int
		{
			trace("\n\n-------sendTrunningCardRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			
			trace("桌子id=" + cmd.deskId
					+ ",牌的花色=" + cmd.cardInfo.colorOfCard
					+ ",牌大小=" + cmd.cardInfo.contentOfCard);				
			
			return 0;
		}
		
		private function sendRiverCardRsp(cmd:SendRiverCardCmd):int
		{
			trace("\n\n-------sendRiverCardRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			
			trace("桌子id=" + cmd.deskId
					+ ",牌的花色=" + cmd.cardInfo.colorOfCard
					+ ",牌大小=" + cmd.cardInfo.contentOfCard);				
			
			return 0;
		}
		
		private function notifyToChooseOptRsp(cmd:NotifyToChooseoperateCmd):int
		{
			trace("\n\n-------notifyToChooseOptRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			
			trace("带入筹码=" + cmd.bringChip
					+ ",最小带入筹码值=" + cmd.minBringChip
					+ ",开始游戏=" + cmd.startPlay
					+ ",下注=" + cmd.inject
					+ ",最小加注额=" + cmd.minInject
					+ ",跟牌=" + cmd.follow
					+ ",过牌=" + cmd.pass
					+ ",全下=" + cmd.sohandle
					+ ",弃牌=" + cmd.giveup);				
			
			return 0;
		}
		
		private function showDownRsp(cmd:ShowDownCmd):int
		{
			trace("\n\n-------showDownRsp-------\n");
			trace("错误号= " + cmd.errorNum);
			
			
			trace("桌子id=" + cmd.deskId);	
			var showDownInfo:ShowDownInfo = null;
			for (var i = 0; i < cmd.showDowndsInfo.length; i++)
			{
				showDownInfo = cmd.showDowndsInfo[i] as ShowDownInfo;
				trace("  桌子位置=" + showDownInfo.seatId
						+ ",玩家id=" + showDownInfo.playerId
						+ ",牌1的花色=" + showDownInfo.firstCard.colorOfCard
						+ ",牌1的大小=" + showDownInfo.firstCard.contentOfCard
						+ ",牌2的花色=" + showDownInfo.secondCard.colorOfCard
						+ ",牌2的大小=" + showDownInfo.secondCard.contentOfCard);
			}
			
			return 0;
		}
		
		private function resultOfGameRsp(cmd:ResultOfGameCmd):int
		{
			trace("\n\n-------resultOfGameRsp-------\n");
			trace("错误号= " + cmd.errorNum);
						
			trace("桌子id=" + cmd.deskId
					+ ",消息N=" + cmd.poolsInfo.length);	
			var poolInfo:PoolInfo = null;
			for (var i = 0; i < cmd.poolsInfo.length; i++)
			{
				poolInfo = cmd.poolsInfo[i] as PoolInfo;
				trace("  池id=" + poolInfo.poolId
						+ ",winner N=" + poolInfo.winnersInfo.length);
				
				var winnerInfo:WinnerInfo = null;
				for (var j:int = 0; j < poolInfo.winnersInfo.length; j++)
				{
					winnerInfo = poolInfo.winnersInfo[j] as WinnerInfo;
					trace("    玩家id=" + winnerInfo.winnerId
						+ ",玩家牌类型=" + winnerInfo.type
						+ ",赢得筹码数量=" + winnerInfo.chipOfWin);
				}
			}
			
			return 0;
		}
		
		//从服务器中发过来的命令。
		private function recvCmd(cmd:abCommand):int
		{
			var ret:int = -1;
			switch(cmd.getCmdType())
			{
				case CommandType.CMD_TYPE_CONNECTSTATUS_RSP:
				ret = connected(cmd as ConnectStatusRsp);
				break;
				case CommandType.CMD_TYPE_GETROOMSOFGAME_RSP:
				ret = getroomsInfoRsp(cmd as GetRoomsOfGameRsp);
				break;
				case CommandType.CMD_TYPE_CREATEROLE_RSP:
				break;
				case CommandType.CMD_TYPE_LOGIN_RSP:
				ret = loginRsp(cmd as LoginCmdRsp);
				break;
				case CommandType.CMD_TYPE_LOGOUT_RSP:
				ret = logoutRsp(cmd as LogoutCmdRsp);
				break;
				case CommandType.CMD_TYPE_ENTERROOM_RSP:
				ret = enterRoomRsp(cmd as EnterRoomCmdRsp);
				break;
				case CommandType.CMD_TYPE_EXITROOM_RSP:
				ret = exitRoomRsp(cmd as ExitRoomCmdRsp);
				break;		
				case CommandType.CMD_TYPE_ENTERDESK_RSP:
				ret = enterDeskRsp(cmd as EnterDeskCmdRsp);
				break;
				case CommandType.CMD_TYPE_EXITDESK_RSP:
				ret = exitDeskRsp(cmd as ExitDeskCmdRsp);
				break;		
				case CommandType.CMD_TYPE_STARTPLAY_RSP:
				ret = startPlayRsp(cmd as StartPlayCmdRsp);
				break;
				case CommandType.CMD_TYPE_INJECT_RSP:
				ret = injectRsp(cmd as InjectCmdRsp);
				break;
				case CommandType.CMD_TYPE_ADDCHIP_RSP:
				ret = addChipRsp(cmd as AddChipCmdRsp);
				break;
				case CommandType.CMD_TYPE_SOHANDLE_RSP:
				ret = sohandleRsp(cmd as SoHandleCmdRsp);
				break;
				case CommandType.CMD_TYPE_GIVEUPPLAY_RSP:
				ret = giveupRsp(cmd as GiveUpPlayCmdRsp);
				break;
				case CommandType.CMD_TYPE_FOLLOW_RSP:
				ret = followRsp(cmd as FollowCmdRsp);
				break;	
				case CommandType.CMD_TYPE_PASS_RSP:
				ret = passRsp(cmd as PassCmdRsp);
				break;
				case CommandType.CMD_TYPE_DESKINOFUPDATE:
				ret = updateDeskInfoRsp(cmd as DeskInofUpdateCmd);
				break;	
				case CommandType.CMD_TYPE_ASSIGNGOUNDCARD:
				ret = assignGroudCardRsp(cmd as AssignGroundCardCmd);
				break;
				case CommandType.CMD_TYPE_ASSIGNPUBLICCARD:
				ret = assignPublicCardRsp(cmd as AssignPublicCardCmd);
				break;
				case CommandType.CMD_TYPE_SENDTURNNINGCARD:
				ret = sendTrunningCardRsp(cmd as SendTurnningCardCmd);
				break;	
				case CommandType.CMD_TYPE_SENDRIVERCARD:
				ret = sendRiverCardRsp(cmd as SendRiverCardCmd);
				break;	
				case CommandType.CMD_TYPE_NOTIFYTOCHOOSEOPERATE:
				ret = notifyToChooseOptRsp(cmd as NotifyToChooseoperateCmd);
				break;
				case CommandType.CMD_TYPE_SHOWDOWN:
				ret = showDownRsp(cmd as ShowDownCmd);
				break;
				case CommandType.CMD_TYPE_RESULTOFGAME:
				ret = resultOfGameRsp(cmd as ResultOfGameCmd);
				break;	
				case CommandType.CMD_TYPE_PLAYERENTERDESK:
				//ret = 
				break;
				case CommandType.CMD_TYPE_PLAYEREXITDESK:
				break;
				case CommandType.CMD_TYPE_POOLINFO:
				break;				
				default:
				break;
			}
			return ret;
		}
/*		
		private function recvDataCallback():void
		{
			var cmdLen:int = 0;
			var recvLen:int = 0;
			var header:ByteArray = new ByteArray;
			recvLen = _tcpSocket.recv(header, 0, 4);
			if (4 != recvLen)
			{
				trace("recvDataCallback error! " + recvLen);
				return ;
			}
			
			cmdLen = header[0] + ((int(header[1])) << 8) + ((int(header[2])) << 16) + ((int(header[3])) << 24);
			
			var cmdBuffer:ByteArray = new ByteArray();
			
			recvLen = _tcpSocket.recv(cmdBuffer, 0, cmdLen);
			if (recvLen != cmdLen)
			{
				trace("recvDataCallback error2!");
				return ;
			}
			
			trace("recv cmd! " + recvLen);
		}
*/		
	}
	
}